Skip to content

fix(people): correct social analytics and activity counts - #290

Open
NeerajCodz wants to merge 3 commits into
mainfrom
fix/people-analytics-issues
Open

NeerajCodz wants to merge 3 commits into
mainfrom
fix/people-analytics-issues

Conversation

@NeerajCodz

Copy link
Copy Markdown
Owner

Changes

  • Correct people query coverage, notifications, social analytics, and profile analytics access.

Issues

Fixes #213
Fixes #214
Fixes #215
Fixes #216
Fixes #217
Fixes #218
Fixes #219
Fixes #221
Fixes #222

- Correct social query coverage, notification counts, and people analytics surfaces.
- Fixes #213, #214, #215, #216, #217, #218, #219, #221, and #222.
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
finapp Ready Ready Preview Nov 27, 2026 2:44am UTC

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-27T02:42:24.426462Z
We couldn’t complete this review. Comment @codex review to try again.
150dbe3 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@NeerajCodz

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8ebc0ff4d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread convex/social/queries.ts
let cursor: string | null = null;
let done = false;
while (!done && !unreadCapped) {
const page = await messageQuery.paginate({ numItems: 50, cursor });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Replace repeated pagination in the hub query

Convex permits only one .paginate() invocation during a query execution, but this call runs once per conversation inside candidates.map; a user with two direct conversations therefore hits an exception on the second invocation. A single conversation can also fail when the loop requests a second page after scanning 50 mostly self-sent messages. As a result, peopleHub and the network screens backed by it fail for ordinary multi-conversation accounts; use bounded non-paginated reads or paginate across separate query executions.

Useful? React with 👍 / 👎.

Comment thread convex/social/queries.ts
.withIndex('by_conversation_createdAt', (q) =>
q.eq('conversationId', scope.id).gt('createdAt', lastReadAt),
)
.collect()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep unread-total reads bounded

When an account has accumulated enough unread messages, this .collect() loads every unread document in every DM, while the group branch does the same for every group. The previous badge queries bounded each thread's reads, but this replacement can exceed Convex's per-query document or byte limits, causing the globally mounted unread-count query to fail for busy or long-unread accounts. Preserve bounded reads or maintain a denormalized aggregate rather than collecting the complete history.

Useful? React with 👍 / 👎.

Comment thread convex/social/queries.ts
lastSeenAt: (settings?.showLastSeen ?? true) ? (presence?.lastSeenAt ?? null) : null,
days,
totalMessages: total,
totalMessagesCapped,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Surface capped message totals to analytics consumers

For conversations with more than 2,000 messages in the 30-day window, the query now returns totalMessagesCapped: true and totalMessages: 2000, but none of the web, native, or profile analytics consumers include this new field in their data types or rendering; they continue displaying “2000 messages” as an exact result. Propagate the flag so capped totals and charts are identified as lower bounds, such as 2000+.

Useful? React with 👍 / 👎.

Comment on lines +242 to +243
Number(item.occurredAt ?? 0) >= startAt &&
Number(item.occurredAt ?? 0) < endAt,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recompute the recent-expense window after module initialization

The newly added filter uses startAt and endAt, which are computed once at module initialization. If the SPA remains loaded and a shared expense is created later, or the user returns to this page without a hard reload, its occurredAt can be at or beyond the stale endAt, so it disappears from the “Last 90 days” count and list even though local records contain it. Compute the bounds per page load/render or refresh them when the range is fetched.

Useful? React with 👍 / 👎.

Comment thread convex/social/queries.ts
Comment on lines +462 to +465
...[...convLow, ...convHigh].map((conversation) => ({
type: 'direct' as const,
id: conversation._id,
})),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude deleted peers from the unread aggregate

When the other participant has soft-deleted their account, their conversation and messages remain in the database, so this scope construction still includes their unread messages. peopleHub filters that deleted user out, leaving no visible conversation through which the viewer can discover or clear the count, while the People badge remains nonzero. Resolve each conversation's peer and omit deleted users, matching the hub's visibility rules.

Useful? React with 👍 / 👎.

Comment on lines +461 to +464
{person.id &&
(sharedGroups.length > 0 ||
status === 'friends' ||
Boolean(analytics?.conversationId)) ? (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor server-reported shared groups when gating analytics

If relationship.sharedGroups reports a shared group but the local group/member cache is still loading, incomplete, or unavailable, personAnalytics is valid and groupCount is nonzero, yet this condition checks only sharedGroups.length. For people who are neither friends nor direct-message contacts, that hides the analytics link despite the server-confirmed shared relationship; gate on the combined/server group result instead.

Useful? React with 👍 / 👎.

Comment thread convex/social/queries.ts
Comment on lines +353 to +360
const candidates = [...peerIds]
.sort(
(a, b) =>
(conversationByPeer.get(b)?.updatedAt ?? 0) -
(conversationByPeer.get(a)?.updatedAt ?? 0) ||
a.localeCompare(b),
)
.slice(0, PEOPLE_HUB_LIMIT * 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rank unread conversations before truncating candidates

For accounts with more than 120 peers, this truncates solely by conversation.updatedAt before unread counts are loaded. An older conversation with unread messages is therefore omitted entirely when 120 newer conversations exist, even though the query's documented and final ordering puts unread conversations first; the aggregate badge can indicate unread messages while the People hub offers no corresponding row. Include unread state in candidate selection or avoid truncating before the unread-first ranking.

Useful? React with 👍 / 👎.

Comment thread convex/social/queries.ts
Comment on lines +595 to +606
let validZone: string | undefined;
for (const candidate of [timeZone, actorSettings?.timezone, actor.timezone]) {
if (!candidate) continue;
try {
new Intl.DateTimeFormat('en-US', { timeZone: candidate });
validZone = candidate;
break;
} catch {
continue;
}
}
const { starts, endAt } = activityDayStarts(now, validZone, tzOffsetMinutes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor caller-provided timezone offsets

All existing web, mobile, and MCP callers provide tzOffsetMinutes, but authenticated users normally have userSettings.timezone, so this precedence always selects the stored zone and silently ignores the supplied offset. When the current device or requested MCP timezone differs from the saved profile zone, message buckets shift to different calendar days while UI date labels still use the device timezone; the MCP tool also violates its contract that the offset controls day buckets. Use the stored zone only when the caller supplies neither an IANA zone nor an offset, or update callers and renderers to use the selected zone consistently.

Useful? React with 👍 / 👎.

- Count unread messages only when expiry metadata is a valid timestamp.
@NeerajCodz

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

- Close the message loop before returning the unread total.
@NeerajCodz

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

This branch was successfully deployed

1 active deployment
Preview — 150dbe3b Deployed Nov 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment